package com.itheima.service.impl;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Override
    public User findByUsername(String username) {
        return userMapper.SelectByUsername(username);
    }

    /**
     * 根据用户id查询角色权限
     * @param id
     * @return
     */
    @Override
    public List<String> getRoleKeysById(Integer id) {
        List<String> roleKeys = userMapper.getRoleKeysById(id);
        if (roleKeys == null){
            log.info("根据用户id查询角色权限为空");
        }else {
            log.info("根据用户id查询角色权限为{}",roleKeys);
        }
        return roleKeys;
    }
}
